<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Customer</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container" id="app">
    <div class="layuimini-main">
        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="" lay-filter="table-search">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">选择区服:</label>
                            <div class="layui-input-inline">
                                <select name="gameArea" class="layui-select">
                                    <option v-for="(item,index) in services" :value="item.server_id" :selected="index==0">{{item.name}}</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">账号ID</label>
                            <div class="layui-input-inline">
                                <input type="text" name="id" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">长ID</label>
                            <div class="layui-input-inline">
                                <input type="text" name="customerId" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">用户名</label>
                            <div class="layui-input-inline">
                                <input type="text" name="username" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">创建时间</label>
                            <div class="layui-input-inline">
                                <input type="text" name="createTimeBegin" id="createTime0"
                                       placeholder="开始时间" autocomplete="off" class="layui-input" />
                                <input type="text" name="createTimeEnd" id="createTime1"
                                       placeholder="截止时间" autocomplete="off" class="layui-input" />
                            </div>
                        </div>

                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="detail" auth="member:detail">查看详情</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="ti" auth="member:ti">踢下线</a>
            <a class="layui-btn layui-btn-xs" lay-event="gm" auth="member:gmOper">GM操作</a>
        </script>
    </div>
</div>
<script id="ti" type="text/html">
    <form class="layui-form" style="margin-top: 5px;" lay-filter="ti-form">
        <div class="layui-form-item">
            <label class="layui-form-label">输入角色名: </label>
            <div class="layui-input-inline">
                <input type="hidden" name="roleId" value="{{d.detail.id}}">
                <input type="hidden" name="successRoleName" value="{{d.detail.nick}}">
                <input type="text" name="roleName" class="layui-input" placeholder="请输入角色名"/>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" id="ti-btn-confirm">确认踢下线</button>
            </div>
        </div>
    </form>
</script>
<script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/js/common.js?v=5" charset="utf-8"></script>
<script>
    new Vue({
        el:"#app",
        data:{
            services:JSON.parse(localStorage.getItem('services')),
        },
        mounted:function () {
            layui.use(['form', 'table','laydate','laytpl'], function () {
                var isLodedTable = false;
                var $ = layui.jquery,
                    form = layui.form,
                    table = layui.table
                    ,laydate=layui.laydate,laytpl=layui.laytpl;

                laydate.render({
                    elem: '#createTime0',
                    value: getYmd(0)
                });
                laydate.render({
                    elem: '#createTime1',
                    value: getYmd(1)
                });

                var loadTable = function(){
                    table.render({
                        where: form.val('table-search'),
                        elem: '#currentTableId',
                        url: '/admin/member/paginate',
                        defaultToolbar: ['filter', 'print' ],
                        cols: [[
                            {field:"id",title:"账号ID",width: 200},
                            {field:"openid",title:"长ID",width: 200},
                            {field:"username",title: '用户名', width: 200},
                            {title: '创建时间',minWidth: 160,templet:function (row) {
                                    return getYMDHMS(row.createtime)
                                }},
                            {title: '最后登录时间',minWidth: 160,templet:function (row) {
                                    return getYMDHMS(row.logintime)
                                }},
                        ]],
                        limits: [10, 15, 20, 25, 50, 100],
                        limit: 15,
                        page: true,
                        skin: 'line'
                    });
                    isLodedTable = true;
                }

                loadTable();

                // 监听搜索操作
                form.on('submit(data-search-btn)', function (data) {
                    if (!isLodedTable){
                        loadTable();
                    } else {
                        //执行搜索重载
                        table.reload('currentTableId', {
                            page: {
                                curr: 1
                            }
                            , where: form.val('table-search')
                        }, 'data');
                    }
                    return false;
                });

                /**
                 * toolbar监听事件
                 */
                table.on('toolbar(currentTableFilter)', function (obj) {
                    if(obj.event === 'export'){ //导出
                        var searchData = form.val('table-search');
                        searchData.page = 1;
                        searchData.limit = 9999999;
                        asyncDownload(
                            '/admin/gameRole/export',
                            searchData,
                            {token:localStorage.getItem('adminToken')}
                        );
                    }
                });

                table.on('tool(currentTableFilter)', function (obj) {
                    var data = obj.data;
                    if (obj.event==='detail'){
                        layer.open({
                            type: 2, // page 层类型
                            area: ['100%', '100%'],
                            title: '游戏角色详情',
                            shade: 0.6, // 遮罩透明度
                            shadeClose: true, // 点击遮罩区域，关闭弹层
                            maxmin: true, // 允许全屏最小化
                            content: "detail.html?id="+data.id + "&gameArea="+$('[name=gameArea]').val()
                        });
                    } else if (obj.event === 'ti') {
                        console.log(
                            obj.data
                        )
                        layer.open({
                            type: 1, // page 层类型
                            title: '角色踢下线',
                            area: ['330px', '220px'],
                            shade: 0.6, // 遮罩透明度
                            shadeClose: false,
                            content: laytpl($('#ti').prop("innerHTML")).render({
                                detail: obj.data
                            })
                        });
                    } else if (obj.event === 'gm') {
                        layer.open({
                            type: 2, // page 层类型
                            area: ['100%', '100%'],
                            title: 'GM操作',
                            shade: 0.6, // 遮罩透明度
                            shadeClose: true, // 点击遮罩区域，关闭弹层
                            maxmin: true, // 允许全屏最小化
                            content: "gm.html?id="+data.id + "&gameArea="+$('[name=gameArea]').val()
                        });
                    }
                });

                $('body').on('click','#ti-btn-confirm',function () {
                    var formData = form.val('ti-form')
                    if (formData.roleName !== formData.successRoleName){
                        layer.msg('角色名称不一致')
                        return false;
                    }
                    var gameArea = $('[name=gameArea]').val()
                    var roleId = formData.roleId;
                    $.post('/admin/gameRole/ti',{gameArea:gameArea,roleId:roleId},function (res) {
                        if (res.code === 0){
                            layer.msg('操作成功',{icon:1,time:500},function(){
                                //location.reload();
                            })
                        }else {
                            layer.msg(res.msg,{icon:5})
                        }
                    })
                    return false;
                })
            });
        }
    })

</script>
</body>
</html>